﻿using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Cmp;
using Renci.SshNet.Messages;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Comm;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Domain.FSJDomain;
using Zocono.WCS.Domain.LogDomain;
using Zocono.WCS.Domain.PlcBytesObject;
using Zocono.WCS.Domain.PlcConnectPoolDomain;
using Zocono.WCS.Domain.ProcessModuleDomain;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WCS.Infrastructure.ApllicationDto.Enums;
using Zocono.WCS.Infrastructure.ApllicationDto.FxModel;
using Zocono.WCS.Infrastructure.ApllicationDto.WCSTaskDto;
using Zocono.WCS.Infrastructure.PlcCommon;
using Zocono.WCS.WMSApiDomain;
using Zocono.WCS.WMSApiDomain.WebApi;


namespace Zocono.WCS.Domain.EquipmentProcessDomain.PlanarGeneralMessage
{
    /// <summary>
    /// 托盘到达分选机请求电芯信息  挑选位握手 1-0
    /// </summary>
    public class FSJWorker_1Service : IPlanarGeneralPlcActionProcessService
    {
        private readonly IRedisHelper _IRedisHelper;
        private readonly ILogUtil _LogUtil;
        private readonly IPlcConnectionPool _PlcConnectionPool;
        private readonly IWorkTaskInfoRepository _WorkTaskInfoRepository;
        private readonly IPlcWriteDbInfoRepository _PlcWriteDbInfoRepository;
        private readonly IPlcConnectionInfoRepository _PlcConnectionInfoRepository;
        private readonly IPlcPointInfoRepositpry _IPlcPointInfoRepositpry;
        private readonly IPlcConnectionStateInfoRepository _IPlcConnectionStateInfoRepository;
        private readonly IRunLogInfoService _IRunLogInfoService;
        private readonly IFSJMesService _IFSJMesService;


        public FSJWorker_1Service(IRedisHelper iRedisHelper, ILogUtil logUtil
            , IPlcConnectionPool plcConnectionPool
            , IWorkTaskInfoRepository workTaskInfoRepository
            , IPlcWriteDbInfoRepository plcWriteDbInfoRepository
            , IPlcConnectionInfoRepository plcConnectionInfoRepository,
            IPlcPointInfoRepositpry plcPointInfoRepositpry
             , IPlcConnectionStateInfoRepository plcConnectionStateInfoRepository
            , IRunLogInfoService runLogInfoService,
            IFSJMesService iFSJMesService//,
            )
        {
            _IRedisHelper = iRedisHelper;
            _LogUtil = logUtil;
            _PlcConnectionPool = plcConnectionPool;
            _WorkTaskInfoRepository = workTaskInfoRepository;
            _PlcWriteDbInfoRepository = plcWriteDbInfoRepository;
            _PlcConnectionInfoRepository = plcConnectionInfoRepository;
            _IPlcPointInfoRepositpry = plcPointInfoRepositpry;
            _IPlcConnectionStateInfoRepository = plcConnectionStateInfoRepository;
            _IRunLogInfoService = runLogInfoService;
            _IFSJMesService = iFSJMesService;
        }
        
        public async Task ProcessActionMessageAsync(BytesObjectBase plcActionMessage, BytesObjectBase wcsActionMessage, EquipmentDbObject planarEquipmentDbObject/*, BytesObjectBase plcStateMassge*/)
        {
            /*
            * 业务需求：
            * 1.托盘进入分选机，分选机获取托盘的信息 调用wms接口 public async Task<ReturnContainer> GetContainerMsg(AutoSelectParaIn autoSelectParaIn)，获得电芯信息
            * 2.根据电芯条码，向MES获取电芯的详细信息（电芯电压，容量 等信息），托盘一到分选机托盘解绑
            * 3、根据电芯详情信息，和档位配置参数，进行分档，并把电芯分档信息写入plc
            * 4、机器人进行分选，托盘解绑，组盘绑定
            * 5、1）留在分选托盘的电芯入库；2）档位上的托盘满盘则留到下一个节点（NG档位走排出，复测档位走下个流程，正常档位流入库）
            * 6、组盘电芯上报到Mes

           /*
            * 处理逻辑
            * 1. 验证plc是否在线
            * 2. 验证当前设备是否报警
            * 3. 验证wcs任务，验证wcs当前子任务(待执行、执行中)，当前子任务已经是SC完成后更新了
            * 4. 组织plc报文，写入plc
            */



            var plcMessage = plcActionMessage as PlanarGeneralPlcActionBO;//Plc的动作报文
            var wcsMessage = wcsActionMessage as PlanarGeneralWcsActionBO;//Wcs的动作报文
            plcMessage.PalletBarcode = plcMessage.PalletBarcode.Trim();
            var ContainerBarcode = plcMessage.PalletBarcode.Trim();
            var EquipmentCode = plcMessage.EquipmentCode.Trim();
            RunLogInfo runLogInfo = new RunLogInfo();
            runLogInfo.ContainerBarcode = plcMessage.PalletBarcode;
            runLogInfo.EquipmentCode = plcMessage.EquipmentCode;

            
            var eqValue = _IRedisHelper.GetStringKey<string>($"PLC-WCS{plcMessage.EquipmentCode}");

            if (eqValue == null || string.IsNullOrEmpty(eqValue))
            {

                //_IRedisHelper.SetStringKey($"PLC-WCS{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(2));
                ////获取电芯数据，并分好档位
                //bool isTrue = await doGetLKFXResult(plcActionMessage, wcsActionMessage, planarEquipmentDbObject);

                //RunLogInfo runLogInfo = new RunLogInfo();
                //runLogInfo.ContainerBarcode = plcMessage.PalletBarcode;
                //runLogInfo.EquipmentCode = plcMessage.EquipmentCode;
                //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】开始执行申请电芯信息");
                //挑选位回PLC握手
                runLogInfo.RunType = "分选机位到达";

                runLogInfo.RunLog = "分选机位到达任务开始";
                var plcConn = _PlcConnectionPool.S7GetWritePlcConnection(plcMessage.PlcConnectionID);
                if (plcConn == null)
                {
                    //runLogInfo.RunLog = $"获取连接({plcMessage.PlcConnectionID})失败";
                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                    _LogUtil.Error($"分选机位到达：托盘【{plcMessage.PalletBarcode}】分选机位到达，PLC设备【{plcMessage.EquipmentCode}】,连接池无连接({plcMessage.PlcConnectionID})");
                    return;
                }
                var plcIPStates = await _IPlcConnectionStateInfoRepository.GetFirstAsync(l => l.PlcConnectionID == plcMessage.PlcConnectionID && l.Connected == true);
                if (plcIPStates == null)
                {
                    //runLogInfo.RunLog = $"{plcConn.IP}plc已离线";
                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                    _LogUtil.Error($"分选机位到达：托盘【{plcMessage.PalletBarcode}】分选机位到达，PLC设备【{plcMessage.EquipmentCode}】,获取连接({plcMessage.PlcConnectionID})失败");
                    return;
                }
                //根据托盘流程实例判定回复目标位
                var objectType = typeof(PlanarGeneralWriteWcsAction).Name;
                var writeConfig = await _PlcWriteDbInfoRepository.GetFirstAsync(s => s.EquipmentCode == plcMessage.EquipmentCode && s.ObjectType == objectType);
                if (writeConfig == null)
                {
                    //runLogInfo.RunLog = $"获取PLC写入配置失败";
                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                    _LogUtil.Error($"分选机位到达：托盘【{plcMessage.PalletBarcode}】分选机位到达，PLC设备【{plcMessage.EquipmentCode}】,获取PLC写入配置失败！请检查配置！");
                    return;
                }

                PlanarGeneralWriteWcsAction writeBo = new PlanarGeneralWriteWcsAction(
                    writeConfig.PlcConnectionId,
                    writeConfig.ID,
                    writeConfig.DbCode,
                    writeConfig.DbStart,
                    objectType,
                    plcMessage.EquipmentCode.ToInt32(),
                    0,
                    //toEquiment.ToInt32(),
                    0,
                    0,
                    "",
                    0,
                    0);

                //校验plc信息是否有托盘码
                if (string.IsNullOrEmpty(plcMessage.PalletBarcode) || plcMessage.PalletBarcode.Length != 10)
                {
                    writeBo.AlrmCode = 102;
                    writeBo.ActionType = 99;
                    var flag = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());
                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                    return;
                }
                try
                {
                    //根据托盘流程实例判定回复目标位 1为分选获取  2为采集回库 3为报错
                    var returnFlag = await WCSMessageWithWMSApi.WCSNoticePalltetArriveFenxuanEquipmentAsync(0, ContainerBarcode, EquipmentCode);

                    if (returnFlag.IsSucceed)
                    {
                        if (returnFlag.Result == 1)
                        {
                            writeBo.ActionType = plcMessage.ActionType;
                            writeBo.ToEquipmentCode = plcMessage.ToEquipmentCode;
                            writeBo.PalletType = plcMessage.PalletType;
                            //先写入分选挡位结果
                            runLogInfo.RunType = "分选机挑选位业务";
                            runLogInfo.RunLog = "分选机挑选位任务开始";
                            
                            //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】处理完达到分选机挑选位业务");
                            try
                            {
                                #region 1.托盘进入分选机，分选机获取托盘的信息 调用wms接口 public async Task<ReturnContainer> GetContainerMsg(AutoSelectParaIn autoSelectParaIn)，获得电芯信息

                                var returnContainer = await WCSMessageWithWMSApi.GetGradeAsync(ContainerBarcode, EquipmentCode);
                                if (!returnContainer.success)
                                {
                                    _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,调用申请电芯结果失败！");
                                    return;
                                }
                                //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】申请到电芯挡位信息");
                                //TODO 写入电芯列表信息
                                var plcConnFx = _PlcConnectionPool.S7GetWritePlcConnection(plcMessage.PlcConnectionID);
                                var objectTypeFx = typeof(PlanarGeneralWriteWcsActionFx).Name;
                                var writeConfigFx = await _PlcWriteDbInfoRepository.GetFirstAsync(it => it.EquipmentCode == "FX-" + plcMessage.EquipmentCode && it.ObjectType == objectTypeFx);
                                if (writeConfigFx == null)
                                {
                                    _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConnFx.IP},写入报文获取写入报文失败");
                                    return;
                                }
                                PlanarGeneralWriteWcsActionFx writeBoFx = new PlanarGeneralWriteWcsActionFx(
                                    writeConfigFx.PlcConnectionId,
                                    writeConfigFx.ID,
                                    writeConfigFx.DbCode,
                                    writeConfigFx.DbStart,
                                    objectTypeFx);

                                writeBoFx.Infos = returnContainer.dxInfos.Select(it => new PlcBytesObject.DxInfo { location = it.location, code = it.code, res = it.res, type = it.type }).ToList();
                                //writeBo.Deserialize();
                                //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】开始写入电芯信息！");
                                var writeResultFx = await plcConnFx.WriteDbToSCAsync(writeBoFx.DbCode, writeBoFx.DbStart, writeBoFx.Deserialize());

                                if (writeResultFx == false)
                                {
                                    //runLogInfo.RunLog = $"PLC(IP{plcConn.IP},写入报文失败";
                                    //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                                    _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConnFx.IP}),写入报文失败");
                                    return;
                                }
                                else
                                {
                                    //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】写入电芯信息成功！");
                                    runLogInfo.RunLog = $"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConnFx.IP},写入报文成功！报文内容：{JsonConvert.SerializeObject(writeBoFx)}";
                                    await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                                    ////如果不是NG挑选 而是分档  则先更新托盘挡位  分选直接解绑了 不用更新电芯挡位了
                                    //if (!returnContainer.IsNgSelect) 
                                    //{
                                    //    //TODO调用WMS更新电芯挡位接口
                                    //    WcsSelectResultUploadInfo upInfo = new WcsSelectResultUploadInfo();
                                    //    upInfo.ContainerCode = plcMessage.PalletBarcode;
                                    //    upInfo.EquipmentCode = plcMessage.EquipmentCode;
                                    //    List<CellsResultMsgDto> CellDatas = new List<CellsResultMsgDto>();
                                    //    foreach (var item in returnContainer.dxInfos)
                                    //    {
                                    //        CellsResultMsgDto temp = new CellsResultMsgDto();
                                    //        temp.CellCode = item.code;
                                    //        temp.CellPosttion = item.location.ToString();
                                    //        temp.Gear = item.Gear;
                                    //        temp.GearName = item.GearName;
                                    //        temp.IsNg = item.IsNg;
                                    //        temp.NgName = item.NgName;
                                    //        CellDatas.Add(temp);
                                    //    }
                                    //    upInfo.CellDataDtos = CellDatas;
                                    //    var upInfoResult = await WCSMessageWithWMSApi.WCSUpdateBatteryGearInfoAsync(upInfo);
                                    //    if (upInfoResult.IsSucceed && upInfoResult.Result)
                                    //    {
                                    //        _LogUtil.Error($"上报电芯挡位信息：托盘【{plcMessage.PalletBarcode}】上报电芯挡位信息成功，PLC设备【{plcMessage.EquipmentCode}】");
                                    //    }
                                    //    else
                                    //    {
                                    //        _LogUtil.Error($"上报电芯挡位信息：托盘【{plcMessage.PalletBarcode}】上报电芯挡位信息失败，PLC设备【{plcMessage.EquipmentCode}】");
                                    //    }
                                    //}
                                }
                                #endregion
                            }
                            catch (Exception ex)
                            {
                                writeBo.ActionType = 99;
                                writeBo.AlrmCode = 132;
                                var re = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());
                                _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                                _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,业务报错：{ex.Message}");
                                return;
                            }

                        }
                        else if (returnFlag.Result == 2)
                        {
                            if (plcMessage.EquipmentCode == "310232" || plcMessage.EquipmentCode == "320662")
                            {
                                writeBo.ActionType = plcMessage.ActionType;
                                writeBo.ToEquipmentCode = 310141;
                            }
                            else
                            {
                                writeBo.ActionType = plcMessage.ActionType;
                                writeBo.ToEquipmentCode = 0;
                            }
                        }
                        else
                        {
                            writeBo.ActionType = 99;
                            writeBo.AlrmCode = 127;
                        }
                        
                        //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】开始回复写入挑选位握手！");
                        //回复挑选位握手
                        var writeResult = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());

                        if (writeResult == false)
                        {
                            //runLogInfo.RunLog = $"PLC(IP{plcConn.IP},写入报文失败";
                            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

                            _LogUtil.Error($"分选机位到达：托盘【{plcMessage.PalletBarcode}】分选机位到达，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConn.IP},写入报文失败");
                            return;
                        }

                        //3. 验证wcs任务,验证wcs当前任务节点是否结束节点
                        var exp = Expressionable.Create<WorkTaskInfo>();
                        exp.AndIF(true, it => it.PalletCode == plcMessage.PalletBarcode && it.TaskState == EnumTaskState.Executing);
                        //exp.AndIF(true, it => it.TaskCode == plcMessage.TaskCode && it.TaskState == EnumTaskState.Executing);
                        var task = await _WorkTaskInfoRepository.GetFirstAsync(exp.ToExpression());
                        if (task != null)
                        {
                            //5.写入成功，结束任务，上报wms
                            task.TaskState = EnumTaskState.Finish;
                            task.UpdateTime = DateTime.Now;
                            task.CurrentDetailTaskState = EnumDetailTaskState.Finish;
                            task.CurrentUpdateTime = DateTime.Now;
                            task.TaskProcessState = EnumTaskProcessState.PlanerCompleted;
                            //更新WCS任务
                            await _WorkTaskInfoRepository.UpdateAsync(task);
                        }
                        //_LogUtil.Debug($"{DateTime.Now}：挑选位【{plcMessage.EquipmentCode}】写入回复挑选位握手成功！");
                        runLogInfo.RunLog = $"分选机位到达：托盘【{plcMessage.PalletBarcode}】分选机位到达，PLC设备【{plcMessage.EquipmentCode}】分选机位到达，写入报文成功！报文内容：{JsonConvert.SerializeObject(writeBo)}";
                        await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
                        //解除锁定
                        //_IRedisHelper.SetStringKey($"PLC-WCS{plcMessage.EquipmentCode}", "", TimeSpan.FromSeconds(10));
                    }
                    else
                    {
                        writeBo.ActionType = 99;
                        writeBo.AlrmCode = 128;
                        var writeResult = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());
                        _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                        _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】到达分选挑选位，PLC设备【{plcMessage.EquipmentCode}】,业务返回失败");
                    }
                }
                catch (Exception ex)
                {
                    writeBo.ActionType = 99;
                    writeBo.AlrmCode = 127;
                    var re = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());
                    _IRedisHelper.SetStringKey($"PLC-{plcMessage.EquipmentCode}", plcMessage.EquipmentCode.ToString() + plcMessage.AlrmCode, TimeSpan.FromSeconds(10));
                    _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】到达分选挑选位，PLC设备【{plcMessage.EquipmentCode}】,业务报错：{ex.Message}");
                    _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】到达分选挑选位，PLC设备【{plcMessage.EquipmentCode}】,业务报错：{ex.StackTrace}");
                    return;
                }
            }
            
            
        }

        //private async Task<bool> doGetLKFXResult(BytesObjectBase plcActionMessage, BytesObjectBase wcsActionMessage, EquipmentDbObject planarEquipmentDbObject)
        //{
        //    var plcMessage = plcActionMessage as PlanarGeneralPlcActionBO;//Plc的动作报文
        //    var wcsMessage = wcsActionMessage as PlanarGeneralWcsActionBO;//Wcs的动作报文
        //    plcMessage.PalletBarcode = plcMessage.PalletBarcode.Trim();
        //    var ContainerBarcode = plcMessage.PalletBarcode.Trim();
        //    var EquipmentCode = plcMessage.EquipmentCode.Trim();
        //    RunLogInfo runLogInfo = new RunLogInfo();
        //    runLogInfo.ContainerBarcode = plcMessage.PalletBarcode;
        //    runLogInfo.EquipmentCode = plcMessage.EquipmentCode;
        //    runLogInfo.RunType = "分选机挑选位业务";

        //    runLogInfo.RunLog = "分选机挑选位任务开始";
        //    try
        //    {
        //        #region 1.托盘进入分选机，分选机获取托盘的信息 调用wms接口 public async Task<ReturnContainer> GetContainerMsg(AutoSelectParaIn autoSelectParaIn)，获得电芯信息

        //        var returnContainer = await WCSMessageWithWMSApi.GetGradeAsync(ContainerBarcode, EquipmentCode);

        //        if (!returnContainer.success)
        //        {
        //            _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,调用申请电芯结果失败！");
        //            return false;
        //        }
        //        //TODO 写入电芯列表信息
        //        var plcConn = _PlcConnectionPool.S7GetWritePlcConnection(plcMessage.PlcConnectionID);
        //        var objectType = typeof(PlanarGeneralWriteWcsActionFx).Name;
        //        var writeConfig = await _PlcWriteDbInfoRepository.GetFirstAsync(it => it.EquipmentCode == "FX-" + plcMessage.EquipmentCode && it.ObjectType == objectType);
        //        if (writeConfig == null)
        //        {
        //            _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConn.IP},写入报文获取写入报文失败");
        //            return false;
        //        }
        //        PlanarGeneralWriteWcsActionFx writeBo = new PlanarGeneralWriteWcsActionFx(
        //            writeConfig.PlcConnectionId,
        //            writeConfig.ID,
        //            writeConfig.DbCode,
        //            writeConfig.DbStart,
        //            objectType);

        //        writeBo.Infos = returnContainer.dxInfos.Select(it => new PlcBytesObject.DxInfo { location = it.location, code = it.code, res = it.res, type = it.type }).ToList();
        //        //writeBo.Deserialize();
        //        var writeResult = await plcConn.WriteDbAsync(writeBo.DbCode, writeBo.DbStart, writeBo.Deserialize());

        //        if (writeResult == false)
        //        {
        //            //runLogInfo.RunLog = $"PLC(IP{plcConn.IP},写入报文失败";
        //            //await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);

        //            _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConn.IP},写入报文失败");
        //            return false;
        //        }
        //        else
        //        {
        //            runLogInfo.RunLog = $"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,PLC(IP{plcConn.IP},写入报文成功！报文内容：{JsonConvert.SerializeObject(writeBo)}";
        //            await _IRunLogInfoService.AddRunLogInfoAsync(runLogInfo);
        //            if (!returnContainer.IsNgSelect) //如果不是NG挑选 而是分档先更新托盘挡位
        //            {
        //                //TODO调用WMS更新电芯挡位接口
        //            }
        //        }
        //        #endregion
        //    }
        //    catch (Exception ex)
        //    {
        //        _LogUtil.Error($"到达分选机工位：托盘【{plcMessage.PalletBarcode}】申请电芯结果，PLC设备【{plcMessage.EquipmentCode}】,业务报错：{ex.Message}");
        //        return false;
        //    }
        //    return true;
        //}

        /// <summary>
        /// 实现分档，返回分档结果
        /// </summary>
        /// <param name="params"></param>
        /// <returns></returns>
        private byte getResult(List<ParamsData> @params)
        {
            //TODO 实现分档，返回分档结果
            return Convert.ToByte(1);
        }
    }
}
